<?php
class Shop_Model_SeoParamForCity extends Shop_Model_Base{

	/**
	 * 表示用変換
	 * @param $cityList
	 * @param $params
	 * @return 変換後リスト
	 */
	public function convertData($cityList, $params)
	{
		return null;
	}

	/**
	 * sql文生成
	 * @param $params
	 * @param $db_params
	 * @return sql文
	 */
	protected function generateSql($params, &$db_params)
	{
		// 市区町村CDが設定されていない場合→終了
		if (empty($params['CityCd'])) return array();
		
		$strQryWhere = '';
		$queryList = array();
		foreach ($params['CityCd'] as $key => $cityCd) {
			$queryList[] = "(M01_TODOUFUKEN_CD = :prefCd{$key} AND M01_SHIKUCHOUSON_CD = :cityCd{$key})";
			$db_params['prefCd'.$key] = substr($cityCd, 0, 2);
			$db_params['cityCd'.$key] = substr($cityCd, 2, 3);
		}
		$strQryWhere = implode(' OR ', $queryList);
		
$sql = <<< DOC_END
	SELECT
		  M01_TODOUFUKEN_CD as TODOUFUKEN_CD
		, M01_SHIKUCHOUSON_CD as LIST_CD
		, M01_TODOUFUKEN as TODOUFUKEN
		, M01_SHIKUCHOUSON as LIST
	FROM
		M01JYUUSHO
	WHERE
		({$strQryWhere})
		AND trim(M01_ABOLISH_YM) is null
		AND M01_OLD_JYUUSHO_CD = M01_JYUUSHO_CD
	GROUP BY
		  M01_TODOUFUKEN_CD
		, M01_SHIKUCHOUSON_CD
		, M01_TODOUFUKEN
		, M01_SHIKUCHOUSON
	ORDER BY
		  M01_TODOUFUKEN_CD
		, M01_SHIKUCHOUSON_CD
DOC_END;
		
		return $sql;
	}
}
?>